package com.my.ads.lib.service;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

import com.my.ads.lib.listen.LockScreenReceiver;

/**
 * Created by xuanyang on 2018/3/7.
 */

public class LockScreenService extends Service {

    public static BroadcastReceiver mReceiver;

    @Override
    public void onDestroy() {
        super.onDestroy();

        unregisterReceiver(mReceiver);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {


        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(Intent.ACTION_POWER_CONNECTED);
        filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
        filter.addAction(Intent.ACTION_BATTERY_LOW);
        filter.addAction(Intent.ACTION_BATTERY_OKAY);
        if (mReceiver == null) {
            mReceiver = new LockScreenReceiver();
            registerReceiver(mReceiver, filter);
        }


        return super.onStartCommand(intent, flags, startId);
    }


}
